SET NOCOUNT ON
GO
USE [CRM_SMS]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Message_Market_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Message_Market_Insert]
GO
CREATE PROCEDURE [dbo].[Message_Market_Insert]
	@MessageMarketID int output,
	@Content nvarchar(200) = null 

AS

INSERT [dbo].[Message_Market]
(
	[Content]

)
VALUES
(
	@Content

)
	SELECT @MessageMarketID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Message_Market_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Message_Market_Update]
GO
CREATE PROCEDURE [dbo].[Message_Market_Update]
	@MessageMarketID int,
	@Content nvarchar(200) = null

AS

UPDATE [dbo].[Message_Market]
SET
	[Content] = @Content
 WHERE 
	[MessageMarketID] = @MessageMarketID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Message_Market_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Message_Market_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Message_Market_SelectByPrimaryKey]
	@MessageMarketID int
AS

	SELECT 
		[MessageMarketID], [Content]
	FROM [dbo].[Message_Market]
	WHERE 
			[MessageMarketID] = @MessageMarketID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Message_Market_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Message_Market_SelectAll]
GO
CREATE PROCEDURE [dbo].[Message_Market_SelectAll]
AS

	SELECT 
		[MessageMarketID], [Content]
	FROM [dbo].[Message_Market]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Message_Market_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Message_Market_SelectByField]
GO
CREATE PROCEDURE [dbo].[Message_Market_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [MessageMarketID], [Content] FROM [dbo].[Message_Market] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Message_Market_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Message_Market_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Message_Market_DeleteByPrimaryKey]
	@MessageMarketID int
AS

DELETE FROM [dbo].[Message_Market]
 WHERE 
	[MessageMarketID] = @MessageMarketID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Message_Market_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Message_Market_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Message_Market_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Message_Market] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Customer_Message_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Customer_Message_Insert]
GO
CREATE PROCEDURE [dbo].[Customer_Message_Insert]
	@CustomerID int ,
	@MessageMarketID int ,
	@Date datetime = null ,
	@MessageStatus bit = null ,
	@Type int = null 

AS

INSERT [dbo].[Customer_Message]
(
	[CustomerID],
	[MessageMarketID],
	[Date],
	[MessageStatus],
	[Type]

)
VALUES
(
	@CustomerID,
	@MessageMarketID,
	@Date,
	@MessageStatus,
	@Type

)


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Customer_Message_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Customer_Message_Update]
GO
CREATE PROCEDURE [dbo].[Customer_Message_Update]
	@CustomerID int,
	@MessageMarketID int,
	@Date datetime = null,
	@MessageStatus bit = null,
	@Type int = null

AS

UPDATE [dbo].[Customer_Message]
SET
	[CustomerID] = @CustomerID,
	[MessageMarketID] = @MessageMarketID,
	[Date] = @Date,
	[MessageStatus] = @MessageStatus,
	[Type] = @Type
 WHERE 
	[CustomerID] = @CustomerID AND 
	[MessageMarketID] = @MessageMarketID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Customer_Message_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Customer_Message_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Customer_Message_SelectByPrimaryKey]
	@CustomerID int,
	@MessageMarketID int
AS

	SELECT 
		[CustomerID], [MessageMarketID], [Date], [MessageStatus], [Type]
	FROM [dbo].[Customer_Message]
	WHERE 
			[CustomerID] = @CustomerID AND 
	[MessageMarketID] = @MessageMarketID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Customer_Message_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Customer_Message_SelectAll]
GO
CREATE PROCEDURE [dbo].[Customer_Message_SelectAll]
AS

	SELECT 
		[CustomerID], [MessageMarketID], [Date], [MessageStatus], [Type]
	FROM [dbo].[Customer_Message]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Customer_Message_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Customer_Message_SelectByField]
GO
CREATE PROCEDURE [dbo].[Customer_Message_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [CustomerID], [MessageMarketID], [Date], [MessageStatus], [Type] FROM [dbo].[Customer_Message] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Customer_Message_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Customer_Message_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Customer_Message_DeleteByPrimaryKey]
	@CustomerID int,
	@MessageMarketID int
AS

DELETE FROM [dbo].[Customer_Message]
 WHERE 
	[CustomerID] = @CustomerID AND 
	[MessageMarketID] = @MessageMarketID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Customer_Message_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Customer_Message_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Customer_Message_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Customer_Message] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sysdiagrams_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[sysdiagrams_Insert]
GO
CREATE PROCEDURE [dbo].[sysdiagrams_Insert]
	@name nvarchar(128) ,
	@principal_id int ,
	@diagram_id int output,
	@version int = null ,
	@definition varbinary(MAX) = null 

AS

INSERT [dbo].[sysdiagrams]
(
	[name],
	[principal_id],
	[version],
	[definition]

)
VALUES
(
	@name,
	@principal_id,
	@version,
	@definition

)
	SELECT @diagram_id=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sysdiagrams_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[sysdiagrams_Update]
GO
CREATE PROCEDURE [dbo].[sysdiagrams_Update]
	@name nvarchar(128),
	@principal_id int,
	@diagram_id int,
	@version int = null,
	@definition varbinary(MAX) = null

AS

UPDATE [dbo].[sysdiagrams]
SET
	[name] = @name,
	[principal_id] = @principal_id,
	[version] = @version,
	[definition] = @definition
 WHERE 
	[diagram_id] = @diagram_id

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sysdiagrams_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[sysdiagrams_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[sysdiagrams_SelectByPrimaryKey]
	@diagram_id int
AS

	SELECT 
		[name], [principal_id], [diagram_id], [version], [definition]
	FROM [dbo].[sysdiagrams]
	WHERE 
			[diagram_id] = @diagram_id

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sysdiagrams_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[sysdiagrams_SelectAll]
GO
CREATE PROCEDURE [dbo].[sysdiagrams_SelectAll]
AS

	SELECT 
		[name], [principal_id], [diagram_id], [version], [definition]
	FROM [dbo].[sysdiagrams]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sysdiagrams_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[sysdiagrams_SelectByField]
GO
CREATE PROCEDURE [dbo].[sysdiagrams_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [name], [principal_id], [diagram_id], [version], [definition] FROM [dbo].[sysdiagrams] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sysdiagrams_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[sysdiagrams_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[sysdiagrams_DeleteByPrimaryKey]
	@diagram_id int
AS

DELETE FROM [dbo].[sysdiagrams]
 WHERE 
	[diagram_id] = @diagram_id

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sysdiagrams_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[sysdiagrams_DeleteByField]
GO
CREATE PROCEDURE [dbo].[sysdiagrams_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[sysdiagrams] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Syntax_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Syntax_Insert]
GO
CREATE PROCEDURE [dbo].[Syntax_Insert]
	@SyntaxID int output,
	@KeyWord nvarchar(50) = null ,
	@SyntaxContent nvarchar(200) = null 

AS

INSERT [dbo].[Syntax]
(
	[KeyWord],
	[SyntaxContent]

)
VALUES
(
	@KeyWord,
	@SyntaxContent

)
	SELECT @SyntaxID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Syntax_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Syntax_Update]
GO
CREATE PROCEDURE [dbo].[Syntax_Update]
	@SyntaxID int,
	@KeyWord nvarchar(50) = null,
	@SyntaxContent nvarchar(200) = null

AS

UPDATE [dbo].[Syntax]
SET
	[KeyWord] = @KeyWord,
	[SyntaxContent] = @SyntaxContent
 WHERE 
	[SyntaxID] = @SyntaxID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Syntax_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Syntax_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Syntax_SelectByPrimaryKey]
	@SyntaxID int
AS

	SELECT 
		[SyntaxID], [KeyWord], [SyntaxContent]
	FROM [dbo].[Syntax]
	WHERE 
			[SyntaxID] = @SyntaxID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Syntax_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Syntax_SelectAll]
GO
CREATE PROCEDURE [dbo].[Syntax_SelectAll]
AS

	SELECT 
		[SyntaxID], [KeyWord], [SyntaxContent]
	FROM [dbo].[Syntax]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Syntax_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Syntax_SelectByField]
GO
CREATE PROCEDURE [dbo].[Syntax_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [SyntaxID], [KeyWord], [SyntaxContent] FROM [dbo].[Syntax] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Syntax_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Syntax_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Syntax_DeleteByPrimaryKey]
	@SyntaxID int
AS

DELETE FROM [dbo].[Syntax]
 WHERE 
	[SyntaxID] = @SyntaxID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Syntax_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Syntax_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Syntax_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Syntax] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Template_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Template_Insert]
GO
CREATE PROCEDURE [dbo].[Template_Insert]
	@ID int output,
	@Subject nvarchar(100) = null ,
	@Template_Content nvarchar(200) = null 

AS

INSERT [dbo].[Template]
(
	[Subject],
	[Template_Content]

)
VALUES
(
	@Subject,
	@Template_Content

)
	SELECT @ID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Template_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Template_Update]
GO
CREATE PROCEDURE [dbo].[Template_Update]
	@ID int,
	@Subject nvarchar(100) = null,
	@Template_Content nvarchar(200) = null

AS

UPDATE [dbo].[Template]
SET
	[Subject] = @Subject,
	[Template_Content] = @Template_Content
 WHERE 
	[ID] = @ID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Template_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Template_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Template_SelectByPrimaryKey]
	@ID int
AS

	SELECT 
		[ID], [Subject], [Template_Content]
	FROM [dbo].[Template]
	WHERE 
			[ID] = @ID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Template_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Template_SelectAll]
GO
CREATE PROCEDURE [dbo].[Template_SelectAll]
AS

	SELECT 
		[ID], [Subject], [Template_Content]
	FROM [dbo].[Template]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Template_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Template_SelectByField]
GO
CREATE PROCEDURE [dbo].[Template_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [ID], [Subject], [Template_Content] FROM [dbo].[Template] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Template_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Template_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Template_DeleteByPrimaryKey]
	@ID int
AS

DELETE FROM [dbo].[Template]
 WHERE 
	[ID] = @ID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Template_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Template_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Template_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Template] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Promotion_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Promotion_Insert]
GO
CREATE PROCEDURE [dbo].[Promotion_Insert]
	@PromotionID int output,
	@PromotionContent nvarchar(200) = null ,
	@ExpirationDate date = null ,
	@Type nvarchar(200) = null 

AS

INSERT [dbo].[Promotion]
(
	[PromotionContent],
	[ExpirationDate],
	[Type]

)
VALUES
(
	@PromotionContent,
	@ExpirationDate,
	@Type

)
	SELECT @PromotionID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Promotion_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Promotion_Update]
GO
CREATE PROCEDURE [dbo].[Promotion_Update]
	@PromotionID int,
	@PromotionContent nvarchar(200) = null,
	@ExpirationDate date = null,
	@Type nvarchar(200) = null

AS

UPDATE [dbo].[Promotion]
SET
	[PromotionContent] = @PromotionContent,
	[ExpirationDate] = @ExpirationDate,
	[Type] = @Type
 WHERE 
	[PromotionID] = @PromotionID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Promotion_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Promotion_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Promotion_SelectByPrimaryKey]
	@PromotionID int
AS

	SELECT 
		[PromotionID], [PromotionContent], [ExpirationDate], [Type]
	FROM [dbo].[Promotion]
	WHERE 
			[PromotionID] = @PromotionID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Promotion_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Promotion_SelectAll]
GO
CREATE PROCEDURE [dbo].[Promotion_SelectAll]
AS

	SELECT 
		[PromotionID], [PromotionContent], [ExpirationDate], [Type]
	FROM [dbo].[Promotion]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Promotion_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Promotion_SelectByField]
GO
CREATE PROCEDURE [dbo].[Promotion_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [PromotionID], [PromotionContent], [ExpirationDate], [Type] FROM [dbo].[Promotion] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Promotion_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Promotion_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Promotion_DeleteByPrimaryKey]
	@PromotionID int
AS

DELETE FROM [dbo].[Promotion]
 WHERE 
	[PromotionID] = @PromotionID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Promotion_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Promotion_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Promotion_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Promotion] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Message_Consult_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Message_Consult_Insert]
GO
CREATE PROCEDURE [dbo].[Message_Consult_Insert]
	@MessageConsultID int output,
	@Phone nvarchar(50) = null ,
	@Content nvarchar(200) = null ,
	@Date datetime = null ,
	@Type int = null ,
	@Replied bit = null 

AS

INSERT [dbo].[Message_Consult]
(
	[Phone],
	[Content],
	[Date],
	[Type],
	[Replied]

)
VALUES
(
	@Phone,
	@Content,
	@Date,
	@Type,
	@Replied

)
	SELECT @MessageConsultID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Message_Consult_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Message_Consult_Update]
GO
CREATE PROCEDURE [dbo].[Message_Consult_Update]
	@MessageConsultID int,
	@Phone nvarchar(50) = null,
	@Content nvarchar(200) = null,
	@Date datetime = null,
	@Type int = null,
	@Replied bit = null

AS

UPDATE [dbo].[Message_Consult]
SET
	[Phone] = @Phone,
	[Content] = @Content,
	[Date] = @Date,
	[Type] = @Type,
	[Replied] = @Replied
 WHERE 
	[MessageConsultID] = @MessageConsultID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Message_Consult_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Message_Consult_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Message_Consult_SelectByPrimaryKey]
	@MessageConsultID int
AS

	SELECT 
		[MessageConsultID], [Phone], [Content], [Date], [Type], [Replied]
	FROM [dbo].[Message_Consult]
	WHERE 
			[MessageConsultID] = @MessageConsultID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Message_Consult_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Message_Consult_SelectAll]
GO
CREATE PROCEDURE [dbo].[Message_Consult_SelectAll]
AS

	SELECT 
		[MessageConsultID], [Phone], [Content], [Date], [Type], [Replied]
	FROM [dbo].[Message_Consult]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Message_Consult_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Message_Consult_SelectByField]
GO
CREATE PROCEDURE [dbo].[Message_Consult_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [MessageConsultID], [Phone], [Content], [Date], [Type], [Replied] FROM [dbo].[Message_Consult] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Message_Consult_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Message_Consult_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Message_Consult_DeleteByPrimaryKey]
	@MessageConsultID int
AS

DELETE FROM [dbo].[Message_Consult]
 WHERE 
	[MessageConsultID] = @MessageConsultID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Message_Consult_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Message_Consult_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Message_Consult_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Message_Consult] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Product_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Product_Insert]
GO
CREATE PROCEDURE [dbo].[Product_Insert]
	@ProductID int output,
	@ProductName nvarchar(100) = null ,
	@Operaton nvarchar(100) = null ,
	@Cpu nvarchar(1000) = null ,
	@Memory nvarchar(1000) = null ,
	@Display nvarchar(1000) = null ,
	@Camera nvarchar(1000) = null ,
	@Batterry nvarchar(1000) = null ,
	@Price nvarchar(1000) = null ,
	@Warranty nvarchar(100) = null ,
	@Deleted bit = null 

AS

INSERT [dbo].[Product]
(
	[ProductName],
	[Operaton],
	[Cpu],
	[Memory],
	[Display],
	[Camera],
	[Batterry],
	[Price],
	[Warranty],
	[Deleted]

)
VALUES
(
	@ProductName,
	@Operaton,
	@Cpu,
	@Memory,
	@Display,
	@Camera,
	@Batterry,
	@Price,
	@Warranty,
	@Deleted

)
	SELECT @ProductID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Product_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Product_Update]
GO
CREATE PROCEDURE [dbo].[Product_Update]
	@ProductID int,
	@ProductName nvarchar(100) = null,
	@Operaton nvarchar(100) = null,
	@Cpu nvarchar(1000) = null,
	@Memory nvarchar(1000) = null,
	@Display nvarchar(1000) = null,
	@Camera nvarchar(1000) = null,
	@Batterry nvarchar(1000) = null,
	@Price nvarchar(1000) = null,
	@Warranty nvarchar(100) = null,
	@Deleted bit = null

AS

UPDATE [dbo].[Product]
SET
	[ProductName] = @ProductName,
	[Operaton] = @Operaton,
	[Cpu] = @Cpu,
	[Memory] = @Memory,
	[Display] = @Display,
	[Camera] = @Camera,
	[Batterry] = @Batterry,
	[Price] = @Price,
	[Warranty] = @Warranty,
	[Deleted] = @Deleted
 WHERE 
	[ProductID] = @ProductID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Product_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Product_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Product_SelectByPrimaryKey]
	@ProductID int
AS

	SELECT 
		[ProductID], [ProductName], [Operaton], [Cpu], [Memory], [Display], [Camera], [Batterry], [Price], [Warranty], [Deleted]
	FROM [dbo].[Product]
	WHERE 
			[ProductID] = @ProductID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Product_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Product_SelectAll]
GO
CREATE PROCEDURE [dbo].[Product_SelectAll]
AS

	SELECT 
		[ProductID], [ProductName], [Operaton], [Cpu], [Memory], [Display], [Camera], [Batterry], [Price], [Warranty], [Deleted]
	FROM [dbo].[Product]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Product_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Product_SelectByField]
GO
CREATE PROCEDURE [dbo].[Product_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [ProductID], [ProductName], [Operaton], [Cpu], [Memory], [Display], [Camera], [Batterry], [Price], [Warranty], [Deleted] FROM [dbo].[Product] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Product_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Product_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Product_DeleteByPrimaryKey]
	@ProductID int
AS

DELETE FROM [dbo].[Product]
 WHERE 
	[ProductID] = @ProductID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Product_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Product_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Product_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Product] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UserAccount_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[UserAccount_Insert]
GO
CREATE PROCEDURE [dbo].[UserAccount_Insert]
	@UserID int output,
	@UserName nvarchar(50) = null ,
	@Password nvarchar(50) = null ,
	@Name nvarchar(50) = null ,
	@Gender bit = null ,
	@Address nvarchar(200) = null ,
	@District nvarchar(50) = null ,
	@City nvarchar(50) = null ,
	@Birthday date = null ,
	@HomePhone nvarchar(50) = null ,
	@CellPhone nvarchar(50) = null ,
	@Email nvarchar(100) = null 

AS

INSERT [dbo].[UserAccount]
(
	[UserName],
	[Password],
	[Name],
	[Gender],
	[Address],
	[District],
	[City],
	[Birthday],
	[HomePhone],
	[CellPhone],
	[Email]

)
VALUES
(
	@UserName,
	@Password,
	@Name,
	@Gender,
	@Address,
	@District,
	@City,
	@Birthday,
	@HomePhone,
	@CellPhone,
	@Email

)
	SELECT @UserID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UserAccount_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[UserAccount_Update]
GO
CREATE PROCEDURE [dbo].[UserAccount_Update]
	@UserID int,
	@UserName nvarchar(50) = null,
	@Password nvarchar(50) = null,
	@Name nvarchar(50) = null,
	@Gender bit = null,
	@Address nvarchar(200) = null,
	@District nvarchar(50) = null,
	@City nvarchar(50) = null,
	@Birthday date = null,
	@HomePhone nvarchar(50) = null,
	@CellPhone nvarchar(50) = null,
	@Email nvarchar(100) = null

AS

UPDATE [dbo].[UserAccount]
SET
	[UserName] = @UserName,
	[Password] = @Password,
	[Name] = @Name,
	[Gender] = @Gender,
	[Address] = @Address,
	[District] = @District,
	[City] = @City,
	[Birthday] = @Birthday,
	[HomePhone] = @HomePhone,
	[CellPhone] = @CellPhone,
	[Email] = @Email
 WHERE 
	[UserID] = @UserID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UserAccount_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[UserAccount_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[UserAccount_SelectByPrimaryKey]
	@UserID int
AS

	SELECT 
		[UserID], [UserName], [Password], [Name], [Gender], [Address], [District], [City], [Birthday], [HomePhone], [CellPhone], [Email]
	FROM [dbo].[UserAccount]
	WHERE 
			[UserID] = @UserID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UserAccount_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[UserAccount_SelectAll]
GO
CREATE PROCEDURE [dbo].[UserAccount_SelectAll]
AS

	SELECT 
		[UserID], [UserName], [Password], [Name], [Gender], [Address], [District], [City], [Birthday], [HomePhone], [CellPhone], [Email]
	FROM [dbo].[UserAccount]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UserAccount_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[UserAccount_SelectByField]
GO
CREATE PROCEDURE [dbo].[UserAccount_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [UserID], [UserName], [Password], [Name], [Gender], [Address], [District], [City], [Birthday], [HomePhone], [CellPhone], [Email] FROM [dbo].[UserAccount] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UserAccount_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[UserAccount_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[UserAccount_DeleteByPrimaryKey]
	@UserID int
AS

DELETE FROM [dbo].[UserAccount]
 WHERE 
	[UserID] = @UserID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UserAccount_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[UserAccount_DeleteByField]
GO
CREATE PROCEDURE [dbo].[UserAccount_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[UserAccount] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Event_Customer_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Event_Customer_Insert]
GO
CREATE PROCEDURE [dbo].[Event_Customer_Insert]
	@EventID int ,
	@CustomerID int ,
	@Code nvarchar(50) = null 

AS

INSERT [dbo].[Event_Customer]
(
	[EventID],
	[CustomerID],
	[Code]

)
VALUES
(
	@EventID,
	@CustomerID,
	@Code

)


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Event_Customer_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Event_Customer_Update]
GO
CREATE PROCEDURE [dbo].[Event_Customer_Update]
	@EventID int,
	@CustomerID int,
	@Code nvarchar(50) = null

AS

UPDATE [dbo].[Event_Customer]
SET
	[EventID] = @EventID,
	[CustomerID] = @CustomerID,
	[Code] = @Code
 WHERE 
	[EventID] = @EventID AND 
	[CustomerID] = @CustomerID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Event_Customer_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Event_Customer_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Event_Customer_SelectByPrimaryKey]
	@EventID int,
	@CustomerID int
AS

	SELECT 
		[EventID], [CustomerID], [Code]
	FROM [dbo].[Event_Customer]
	WHERE 
			[EventID] = @EventID AND 
	[CustomerID] = @CustomerID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Event_Customer_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Event_Customer_SelectAll]
GO
CREATE PROCEDURE [dbo].[Event_Customer_SelectAll]
AS

	SELECT 
		[EventID], [CustomerID], [Code]
	FROM [dbo].[Event_Customer]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Event_Customer_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Event_Customer_SelectByField]
GO
CREATE PROCEDURE [dbo].[Event_Customer_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [EventID], [CustomerID], [Code] FROM [dbo].[Event_Customer] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Event_Customer_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Event_Customer_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Event_Customer_DeleteByPrimaryKey]
	@EventID int,
	@CustomerID int
AS

DELETE FROM [dbo].[Event_Customer]
 WHERE 
	[EventID] = @EventID AND 
	[CustomerID] = @CustomerID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Event_Customer_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Event_Customer_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Event_Customer_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Event_Customer] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Event_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Event_Insert]
GO
CREATE PROCEDURE [dbo].[Event_Insert]
	@EventID int output,
	@Subject nvarchar(50) = null ,
	@Content nvarchar(200) = null ,
	@Description nvarchar(1000) = null ,
	@BeginDate date = null ,
	@FinishDate date = null ,
	@EventStatus bit = null ,
	@PromotionID int = null ,
	@FormatSMS1 nvarchar(200) = null ,
	@FormatSMS2 nvarchar(200) = null ,
	@FormatSMS3 nvarchar(200) = null ,
	@FormatSMS4 nvarchar(200) = null 

AS

INSERT [dbo].[Event]
(
	[Subject],
	[Content],
	[Description],
	[BeginDate],
	[FinishDate],
	[EventStatus],
	[PromotionID],
	[FormatSMS1],
	[FormatSMS2],
	[FormatSMS3],
	[FormatSMS4]

)
VALUES
(
	@Subject,
	@Content,
	@Description,
	@BeginDate,
	@FinishDate,
	@EventStatus,
	@PromotionID,
	@FormatSMS1,
	@FormatSMS2,
	@FormatSMS3,
	@FormatSMS4

)
	SELECT @EventID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Event_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Event_Update]
GO
CREATE PROCEDURE [dbo].[Event_Update]
	@EventID int,
	@Subject nvarchar(50) = null,
	@Content nvarchar(200) = null,
	@Description nvarchar(1000) = null,
	@BeginDate date = null,
	@FinishDate date = null,
	@EventStatus bit = null,
	@PromotionID int = null,
	@FormatSMS1 nvarchar(200) = null,
	@FormatSMS2 nvarchar(200) = null,
	@FormatSMS3 nvarchar(200) = null,
	@FormatSMS4 nvarchar(200) = null

AS

UPDATE [dbo].[Event]
SET
	[Subject] = @Subject,
	[Content] = @Content,
	[Description] = @Description,
	[BeginDate] = @BeginDate,
	[FinishDate] = @FinishDate,
	[EventStatus] = @EventStatus,
	[PromotionID] = @PromotionID,
	[FormatSMS1] = @FormatSMS1,
	[FormatSMS2] = @FormatSMS2,
	[FormatSMS3] = @FormatSMS3,
	[FormatSMS4] = @FormatSMS4
 WHERE 
	[EventID] = @EventID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Event_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Event_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Event_SelectByPrimaryKey]
	@EventID int
AS

	SELECT 
		[EventID], [Subject], [Content], [Description], [BeginDate], [FinishDate], [EventStatus], [PromotionID], [FormatSMS1], [FormatSMS2], [FormatSMS3], [FormatSMS4]
	FROM [dbo].[Event]
	WHERE 
			[EventID] = @EventID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Event_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Event_SelectAll]
GO
CREATE PROCEDURE [dbo].[Event_SelectAll]
AS

	SELECT 
		[EventID], [Subject], [Content], [Description], [BeginDate], [FinishDate], [EventStatus], [PromotionID], [FormatSMS1], [FormatSMS2], [FormatSMS3], [FormatSMS4]
	FROM [dbo].[Event]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Event_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Event_SelectByField]
GO
CREATE PROCEDURE [dbo].[Event_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [EventID], [Subject], [Content], [Description], [BeginDate], [FinishDate], [EventStatus], [PromotionID], [FormatSMS1], [FormatSMS2], [FormatSMS3], [FormatSMS4] FROM [dbo].[Event] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Event_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Event_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Event_DeleteByPrimaryKey]
	@EventID int
AS

DELETE FROM [dbo].[Event]
 WHERE 
	[EventID] = @EventID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Event_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Event_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Event_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Event] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Customer_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Customer_Insert]
GO
CREATE PROCEDURE [dbo].[Customer_Insert]
	@CustomerID int output,
	@FirstName nvarchar(50) = null ,
	@LastName nvarchar(50) = null ,
	@CellPhone nvarchar(20) = null ,
	@Gender bit = null ,
	@Birthday date = null ,
	@Addrress nvarchar(100) = null ,
	@District nvarchar(20) = null ,
	@City nvarchar(50) = null ,
	@Phone nvarchar(20) = null ,
	@Company nvarchar(50) = null ,
	@Email nvarchar(50) = null ,
	@User nvarchar(50) = null ,
	@Deleted bit 

AS

INSERT [dbo].[Customer]
(
	[FirstName],
	[LastName],
	[CellPhone],
	[Gender],
	[Birthday],
	[Addrress],
	[District],
	[City],
	[Phone],
	[Company],
	[Email],
	[User],
	[Deleted]

)
VALUES
(
	@FirstName,
	@LastName,
	@CellPhone,
	@Gender,
	@Birthday,
	@Addrress,
	@District,
	@City,
	@Phone,
	@Company,
	@Email,
	@User,
	@Deleted

)
	SELECT @CustomerID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Customer_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Customer_Update]
GO
CREATE PROCEDURE [dbo].[Customer_Update]
	@CustomerID int,
	@FirstName nvarchar(50) = null,
	@LastName nvarchar(50) = null,
	@CellPhone nvarchar(20) = null,
	@Gender bit = null,
	@Birthday date = null,
	@Addrress nvarchar(100) = null,
	@District nvarchar(20) = null,
	@City nvarchar(50) = null,
	@Phone nvarchar(20) = null,
	@Company nvarchar(50) = null,
	@Email nvarchar(50) = null,
	@User nvarchar(50) = null,
	@Deleted bit

AS

UPDATE [dbo].[Customer]
SET
	[FirstName] = @FirstName,
	[LastName] = @LastName,
	[CellPhone] = @CellPhone,
	[Gender] = @Gender,
	[Birthday] = @Birthday,
	[Addrress] = @Addrress,
	[District] = @District,
	[City] = @City,
	[Phone] = @Phone,
	[Company] = @Company,
	[Email] = @Email,
	[User] = @User,
	[Deleted] = @Deleted
 WHERE 
	[CustomerID] = @CustomerID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Customer_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Customer_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Customer_SelectByPrimaryKey]
	@CustomerID int
AS

	SELECT 
		[CustomerID], [FirstName], [LastName], [CellPhone], [Gender], [Birthday], [Addrress], [District], [City], [Phone], [Company], [Email], [User], [Deleted]
	FROM [dbo].[Customer]
	WHERE 
			[CustomerID] = @CustomerID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Customer_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Customer_SelectAll]
GO
CREATE PROCEDURE [dbo].[Customer_SelectAll]
AS

	SELECT 
		[CustomerID], [FirstName], [LastName], [CellPhone], [Gender], [Birthday], [Addrress], [District], [City], [Phone], [Company], [Email], [User], [Deleted]
	FROM [dbo].[Customer]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Customer_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Customer_SelectByField]
GO
CREATE PROCEDURE [dbo].[Customer_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [CustomerID], [FirstName], [LastName], [CellPhone], [Gender], [Birthday], [Addrress], [District], [City], [Phone], [Company], [Email], [User], [Deleted] FROM [dbo].[Customer] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Customer_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Customer_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Customer_DeleteByPrimaryKey]
	@CustomerID int
AS

DELETE FROM [dbo].[Customer]
 WHERE 
	[CustomerID] = @CustomerID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Customer_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Customer_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Customer_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Customer] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO
